<template>
  <div class="recommend">
    <h3 v-if="title" class="recommend-title">
      {{ title }}
    </h3>
    <ul>
      <li v-for="(item,index) in list" :key="index" class="recommend-item" @click="toCourseDetail(item)">
        <div class="img-box">
          <img :src="item.cover" alt="">
        </div>
        <div class="recommend-content">
          <p class="name ellipsis">
            {{ item.name }}
          </p>
          <p class="desc">
            <span v-if="item.price != 0" class="price">¥ {{ item.price + '.00' }}</span>
            <span v-if="item.price == 0" class="price">免费学习</span>

            <span v-if="item.level === 0 " class="rank">{{ `入门` }}</span>
            <span v-if="item.level === 1 " class="rank">{{ `初级` }}</span>
            <span v-if="item.level === 2 " class="rank">{{ `中级` }}</span>
            <span v-if="item.level === 3 " class="rank">{{ `高级` }}</span>

            <span class="number">
              <i class="iconfont">&#xe607;</i>
              {{ item.buySum }}
            </span>

          </p>
        </div>
      </li>
    </ul>
  </div>
</template>
<script>
export default {
  props: {
    title: {
      type: String,
      default: ''
    },
    list: {
      type: Array,
      default () {
        return []
      }
    }
  },
  methods: {
    toCourseDetail(item){
      let url = this.$router.resolve({
        path: '/course/'+ item.courseId,
      });
      window.open(url.href, '_blank')
    }
  }
}
</script>
<style lang="stylus" scoped>
  .recommend
    .recommend-title
      margin-bottom: 12px;
      font-size: 14px;
      font-weight: 700;
    .recommend-item
      display: flex;
      align-items: center;
      margin-bottom: 8px;
      cursor: pointer;
      .img-box
        flex: 0 0 80px;
        width: 80px;
        height: 60px;
        & > img
          object-fit cover
          display: block;
          width: 100%;
          height: 100%;
          background-color: #ccc;
          border-radius: 6px;
      .recommend-content
        flex: 1;
        margin-left: 20px;
        .name
          margin-bottom: 4px;
          max-width: 220px;
          font-size: 14px;
          color: #545C63;
          line-height: 24px;
        .desc
          & > span
            display: inline-block;
            vertical-align: middle;
            margin-right: 10px;
            font-size: 12px;
            color: #545C63;
            &.price
              font-weight: 800;
</style>
